home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-17 | 23.0 KB | 964 lines | [TEXT/KAHL] |
- /******************************************************************************
- GNUEditApp.c
-
- Application methods for a tiny editor.
-
- Copyright © 1989 Symantec Corporation. All rights reserved.
-
- ******************************************************************************/
-
- #include <CAppleEvent.h>
- #include <Commands.h>
- #include <CBartender.h>
- #include <Aliases.h>
- #include <Global.h>
- #include <Exceptions.h>
- #include <Folders.h>
- #include <CResFile.h>
- #include <TBUtilities.h>
- #include <CScrollPane.h>
- #include <CDialogText.h>
- #include <CDialog.h>
- #include <CPaneBorder.h>
- #include <CApplication.h>
- #include <CTextEnvirons.h>
- #include <CButton.h>
- #include <CCheckBox.h>
- #include <CRadioControl.h>
- #include <CRadioGroupPane.h>
- #include <CDialogText.h>
- #include <CPopupMenu.h>
- #include <CPopupPane.h>
- #include <CArrowPopupPane.h>
- #include <CBartender.h>
- #include <CTable.h>
- #include <CDataFile.h>
- #include <CAbstractText.h>
-
- #include "CObjectDoc.h"
- #include "GNUEditApp.h"
- #include "CDRVRBrowser.h"
- #include "CPathArray.h"
- #include "CPathDirector.h"
- #include "CBrowseResDoc.h"
- #include "GNUEditDoc.h"
- #include "CDRVRDirector.h"
- #include "CAboutDirector.h"
- #include "CConfigDirector.h"
-
- void GNUEditApp::ForceClassReferences( void)
- {
- Boolean alwaysFalse = FALSE;
- CObject *dummy;
-
- if (alwaysFalse)
- {
- member( dummy, CButton);
- member( dummy, CCheckBox);
- member( dummy, CRadioControl);
- member( dummy, CRadioGroupPane);
- member( dummy, CDialogText);
- member( dummy, CPopupMenu);
- member( dummy, CPopupPane);
- member( dummy, CArrowPopupPane);
- member( dummy, CScrollPane);
- }
- }
-
- #define cmdLD 10003
- #define cmdLDR 10004
- #define cmdAR 10005
- #define configCPP 10100
- #define configCC1 10101
- #define configAS 10102
- #define configLD 10103
- #define configSEARCH 9998
-
- extern OSType gSignature;
- extern CBartender *gBartender;
- extern CApplication *gApplication; /* The application */
- extern CDesktop *gDesktop;
-
- CPathArray *gStrings;
- short prefsRefNum;
-
- #define kExtraMasters 10
- #define kRainyDayFund 45000
- #define kCriticalBalance 40000
- #define kToolboxBalance 20000
- #define kStackSize 32000
-
- /***
- * IGNUEditApp
- *
- * Initialize the application. Your initialization method should
- * at least call the inherited method. If your application class
- * defines its own instance variables or global variables, this
- * is a good place to initialize them.
- *
- ***/
-
- void GNUEditApp::IGNUEditApp(void)
-
- {
- SetApplLimit((Ptr) (CurStackBase-kStackSize));
- CApplication::IApplication( kExtraMasters, kRainyDayFund,
- kCriticalBalance, kToolboxBalance);
- for (ccnt = 8; ccnt--; ) nxt[ccnt] = GetCursor(128+ccnt);
- }
-
- /* document searching */
-
- static FSSpec FileToFind;
- static GNUEditDoc *FoundDoc;
-
- static void GNUEditSearch(CObject *theObject)
- {
- register CWindow *theWindow = (CWindow *)theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, GNUEditDoc))
- {
- GNUEditDoc *theDocument = (GNUEditDoc *)theDirector;
- Str255 theTitle;
- theWindow->GetTitle(theTitle);
- if(EqualString(FileToFind.name,theTitle,TRUE,TRUE))
- {
- FoundDoc = theDocument;
- }
- }
- }
-
- static CDRVRDirector *FoundDRVR;
-
- static void CDRVRSearch(CObject *theObject)
- {
- register CWindow *theWindow = (CWindow *)theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, CDRVRDirector))
- {
- CDRVRDirector *theDocument = (CDRVRDirector *)theDirector;
- Str255 theTitle;
- theWindow->GetTitle(theTitle);
- if(EqualString(FileToFind.name,theTitle,TRUE,TRUE))
- {
- FoundDRVR = theDocument;
- }
- }
- }
-
- static CObjectDoc *FoundAR;
-
- static void CARSearch(CObject *theObject)
- {
- register CWindow *theWindow = (CWindow *)theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, CObjectDoc))
- {
- CObjectDoc *theDocument = (CObjectDoc *)theDirector;
- Str255 theTitle;
- theWindow->GetTitle(theTitle);
- if(EqualString(FileToFind.name,theTitle,TRUE,TRUE))
- {
- FoundAR = theDocument;
- }
- }
- }
-
- static Handle FoundDRVRBrowser;
-
- static void CDRVRBrowserSearch(CObject *theObject)
- {
- register CWindow *theWindow = (CWindow *)theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, CDRVRBrowser))
- {
- CDRVRBrowser *theDocument = (CDRVRBrowser *)theDirector;
- tResourceInfo resInfo;
- Cell selectedCell;
- // determine the selected cells
-
- selectedCell.h = selectedCell.v = 0;
- while (theDocument->GetSelect( kCurrentOrNext, &selectedCell, &resInfo))
- {
- resInfo.name[1] = *resInfo.name-1;
- if(EqualString(FileToFind.name,&resInfo.name[1],TRUE,TRUE))
- {
- FoundDRVRBrowser = resInfo.resource;
- LoadResource(FoundDRVRBrowser);
- }
- }
- }
- }
-
- static CBrowseResDoc *FoundRes;
-
- static void CBrowseResSearch(CObject *theObject)
- {
- register CWindow *theWindow = (CWindow *) theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, CBrowseResDoc))
- {
- FoundRes = (CBrowseResDoc *)theDirector;
- }
- }
-
- static void SearchPaths(FSSpec *myfile)
- {
- Boolean strict1,strict = TRUE;
- do
- {
- FSSpec itemPtr;
- Boolean targetIsFolder;
- Boolean wasAliased;
- OSErr iErr;
- long cnt = gStrings->GetNumItems();
- long i = 1;
- do
- {
- gStrings->GetItem( &itemPtr, i);
- BlockMove(FileToFind.name, itemPtr.name, 1+*FileToFind.name);
- iErr = ResolveAliasFile(&itemPtr,TRUE,&targetIsFolder,&wasAliased);
- }
- while ((iErr || targetIsFolder ||
- !EqualString(FileToFind.name, itemPtr.name, strict, TRUE)) && (++i <= cnt));
- if (i <= cnt)
- {
- *myfile = itemPtr;
- return;
- }
- strict1 = strict;
- strict = FALSE;
- }
- while (strict != strict1);
- myfile->name[0] = 0;
- }
-
- Handle SearchForName(FSSpec *myfile);
- #define O_TEXT 0x0100
- #define O_BINARY 0x0000
- #define O_RESOURCE 0x1000
- Handle SearchForName(FSSpec *myfile)
- {
- FileToFind = *myfile;
- FoundDoc = 0;
- gDesktop->itsWindows->DoForEach(GNUEditSearch);
- if (FoundDoc)
- {
- myfile->vRefNum = O_TEXT;
- return ((CAbstractText *)(FoundDoc->itsMainPane))->GetTextHandle();
- }
- FoundDRVR = 0;
- gDesktop->itsWindows->DoForEach(CDRVRSearch);
- if (FoundDRVR)
- {
- myfile->vRefNum = O_RESOURCE;
- return FoundDRVR->itsData;
- }
- FoundAR = 0;
- gDesktop->itsWindows->DoForEach(CARSearch);
- if (FoundAR)
- {
- myfile->vRefNum = 0;
- return FoundAR->itsData;
- }
- FoundDRVRBrowser = 0;
- gDesktop->itsWindows->DoForEach(CDRVRBrowserSearch);
- if (FoundDRVRBrowser)
- {
- myfile->vRefNum = O_RESOURCE;
- return FoundDRVRBrowser;
- }
- SearchPaths(myfile);
- return 0;
- }
-
- static void copyresfile(short in, short out)
- {
- short numTypes,currIndex;
- UseResFile(in);
- numTypes = Count1Types();
- for( currIndex = 1; currIndex <= numTypes; currIndex++)
- {
- short numRes,Index;
- ResType theType;
- Get1IndType( &theType, currIndex);
- FailOSErr(ResError());
- numRes = Count1Resources( theType);
- if (theType != 'UNIX') for( Index = 1; Index <= numRes; Index++)
- {
- short rID;
- Str255 rName;
- Handle aResource;
- Handle resource = Get1IndResource( theType, Index);
- FailNIL(resource);
- GetResInfo(resource,&rID,&theType,rName);
- DetachResource(resource);
- if ((theType == 'SIZE') && (rID >= -1) && (rID <= 1))
- {
- Handle pref_resource;
- extern long atol(char *);
- struct size
- {
- unsigned short mask;
- long size,minsize;
- } temp;
- int i;
- temp.mask = 0;
- for (i = 99; i < 115; i++)
- {
- temp.mask <<= 1;
- temp.mask |= gOptions[i]&1;
- }
- pref_resource = GetResource('PREF', 3);
- FailNILRes(pref_resource);
- temp.minsize = 1024L*atol(*pref_resource);
- pref_resource = GetResource('PREF', rID+4);
- FailNILRes(pref_resource);
- temp.size = 1024L*atol(*pref_resource);
- BlockMove(&temp, *resource, sizeof(struct size));
- }
-
- UseResFile(out);
-
- aResource = Get1Resource(theType,rID);
- if (!aResource)
- {
- AddResource(resource,theType,rID,rName);
- }
- else
- {
- SetHandleSize(aResource, 0);
- HandAndHand(resource, aResource);
- ChangedResource(aResource);
- DisposHandle(resource);
- }
- UseResFile(in);
- }
- }
- }
-
- static Str255 defaultLibname;
-
- void CreateGlobalDocument(Handle text);
- void CreateGlobalDocument(Handle text)
- {
- long newsize;
- CWindow *newwin;
- Str255 name;
- BlockMove(*text, name, 1+**text);
- newsize = GetHandleSize(text)-*name-1;
- BlockMove(1+*name+*text, *text, newsize);
- SetHandleSize(text, newsize);
- if (EqualString(name,"\plibrary.a_supersede",TRUE,TRUE))
- {
- FSSpec myfile;
- FInfo info;
- short in;
- SFReply macSFReply; /* Standard File reply record */
- CDataFile *itsFile;
- Point corner; /* Top left corner of dialog box */
- StringHandle prompt; /* Prompt string */
-
- /* Center dialog box on the screen */
- FindDlogPosition('DLOG', putDlgID, &corner);
-
- prompt = GetString(STRprompt);
- FailNILRes( prompt);
-
- MoveHHi( (Handle) prompt);
- HLock((Handle) prompt);
-
- if (*defaultLibname < 7) BlockMove("\plibrary_____", name, 16);
- else BlockMove(defaultLibname, name, *defaultLibname);
- BlockMove(".a", &name[*name-6], 2);
- *name -= 5;
-
- SFPPutFile(corner, *prompt, name, NULL, &macSFReply, putDlgID, NULL);
- HUnlock((Handle) prompt);
- if (!macSFReply.good) return;
- itsFile = new(CDataFile);
- itsFile->IDataFile();
- itsFile->SFSpecify(&macSFReply);
- if (itsFile->ExistsOnDisk()) itsFile->ThrowOut();
-
- itsFile->CreateNew(gSignature, 'AR ');
- itsFile->Open(fsRdWrPerm);
- itsFile->WriteAll(text);
- itsFile->Dispose();
- }
- else if (EqualString(name,"\pa.out",TRUE,TRUE))
- {
- FSSpec myfile;
- FInfo info;
- short in;
- short last = CurResFile();
- SFReply macSFReply; /* Standard File reply record */
- CResFile *itsFile,*userFile;
- Point corner; /* Top left corner of dialog box */
- StringHandle prompt; /* Prompt string */
-
- /* Center dialog box on the screen */
- FindDlogPosition('DLOG', putDlgID, &corner);
-
- prompt = (StringHandle)GetResource('PREF', 2);
- FailNILRes( prompt);
- *name = GetHandleSize((Handle) prompt);
- BlockMove(*(Handle)prompt, name+1, *name);
-
- prompt = GetString(STRprompt);
- FailNILRes( prompt);
-
- MoveHHi( (Handle) prompt);
- HLock((Handle) prompt);
- SFPPutFile(corner, *prompt, name, NULL, &macSFReply, putDlgID, NULL);
- HUnlock((Handle) prompt);
- if (!macSFReply.good) return;
- itsFile = new(CResFile);
- itsFile->IResFile();
- itsFile->SFSpecify(&macSFReply);
- if (itsFile->ExistsOnDisk()) itsFile->ThrowOut();
-
- prompt = (StringHandle)GetResource('PREF', 1);
- FailNILRes( prompt);
- BlockMove(*(Handle) prompt, name, 4);
-
- itsFile->CreateNew(*(long *)name, 'APPL');
- itsFile->Open(fsRdWrPerm);
-
- userFile = new(CResFile);
- userFile->IResFile();
-
- prompt = (StringHandle)GetResource('PREF', 6);
- FailNILRes( prompt);
- *FileToFind.name = GetHandleSize((Handle) prompt);
- BlockMove(*(Handle)prompt, FileToFind.name+1, *FileToFind.name);
- SearchPaths(&myfile);
- userFile->SpecifyFSSpec(&myfile);
- if (userFile->ExistsOnDisk())
- {
- userFile->Open(fsRdPerm);
- copyresfile(userFile->refNum, itsFile->refNum);
- }
- userFile->Dispose();
- in = OpenResFile("\ploader");
- if (in == -1) FailOSErr(ResError());
- copyresfile(in, itsFile->refNum);
-
- itsFile->MakeCurrent();
- AddResource(text, 'UNIX', 128, "\pRelocatable code module");
- itsFile->Dispose();
- UseResFile(last);
- }
- else if ((name[*name]=='o') && (name[*name-1]=='.'))
- {
- Handle stub = GetResource('UNIX', 12);
- DetachResource(stub);
- FailOSErr(HandAndHand(text,stub));
- FoundRes = 0;
- gDesktop->itsWindows->DoForEach(CBrowseResSearch);
- if (FoundRes) FoundRes->AddType(stub, 'DRVR', name);
- else
- {
- CDRVRDirector *dialog = new( CDRVRDirector);
- dialog->NewDocument( stub, gApplication, name );
- dialog->BeginDialog();
- }
- }
- else
- {
- ((GNUEditApp *)gApplication)->CreateDocumentfromHandle(text);
- newwin = gDesktop->GetTopWindow();
- newwin->SetTitle(name);
- }
- }
-
- void GNUEditApp::SpinCursor(void)
- {
- SetCursor(*nxt[7&++ccnt]);
- }
-
- /***
- * SetUpFileParameters
- *
- * In this routine, you specify the kinds of files your
- * application opens.
- *
- *
- ***/
-
- void GNUEditApp::SetUpFileParameters(void)
-
- {
- inherited::SetUpFileParameters(); /* Be sure to call the default method */
-
- /**
- ** sfNumTypes is the number of file types
- ** your application knows about.
- ** sfFileTypes[] is an array of file types.
- ** You can define up to 4 file types in
- ** sfFileTypes[].
- **
- **/
-
- sfNumTypes = 4;
- sfFileTypes[0] = 'TEXT';
- sfFileTypes[1] = 'AR ';
- sfFileTypes[2] = 'DFIL';
- sfFileTypes[3] = 'rsrc';
-
- /**
- ** Although it's not an instance variable,
- ** this method is a good place to set the
- ** gSignature global variable. Set this global
- ** to your application's signature. You'll use it
- ** to create a file (see CFile::CreateNew()).
- **
- **/
-
- gSignature = 'JRRK';
- }
-
-
- /***
- * SetUpMenus
- *
- * In this method, you add special menu items and set the
- * menu item dimming and checking options for your menus.
- * The most common special menu items are the names of the
- * fonts. For this tiny editor, you also want to set up the
- * dimming and checking options so only the current font
- * and size are checked.
- *
- ***/
-
- void GNUEditApp::SetUpMenus(void)
-
- {
- /**
- ** Let the default method read the menus from
- ** the MBAR 1 resource.
- **
- **/
-
- inherited::SetUpMenus();
-
- /**
- ** Add the fonts in the system to the
- ** Font menu. Remember, MENUfont is one
- ** of the reserved font numbers.
- **
- **/
-
- AddResMenu(GetMHandle(MENUfont), 'FONT');
-
- /**
- ** The UpdateMenus() method sets up the dimming
- ** for menu items. By default, the bartender dims
- ** all the menus, and each bureaucrat is reponsible
- ** for turning on the items that correspond to the commands
- ** it can handle.
- **
- ** Set up the options here. The edit pane's UpdateMenus()
- ** method takes care of doing the work.
- **
- ** For Font and Size menus, you want all the items to
- ** be enabled all the time. In other words, you don't
- ** want the bartender to ever dim any of the items
- ** in these two menus.
- **
- **/
-
- gBartender->SetDimOption(MENUfont, dimNONE);
- gBartender->SetDimOption(MENUsize, dimNONE);
- gBartender->SetDimOption(MENUstyle, dimNONE);
- gBartender->SetDimOption(MENUfilter, dimNONE);
- gBartender->SetDimOption(MENUconfig, dimNONE);
-
- /**
- ** For Font and Size menus, one of the items
- ** is always checked. Setting the unchecking option
- ** to TRUE lets the bartender know that it should
- ** uncheck all the menu items because an UpdateMenus()
- ** method will check the right items.
- ** For the Style menu, uncheck all the items and
- ** let the edit pane's UpdateMenus() method check the
- ** appropriate ones.
- **
- **/
-
- gBartender->SetUnchecking(MENUfont, TRUE);
- gBartender->SetUnchecking(MENUsize, TRUE);
- gBartender->SetUnchecking(MENUstyle, TRUE);
- }
-
-
-
- /***
- * CreateDocument
- *
- * The user chose New from the File menu.
- * In this method, you need to create a document and send it
- * a NewFile() message.
- *
- ***/
-
- void GNUEditApp::CreateDocument()
- {
- CreateDocumentfromHandle(NULL);
- }
-
- void GNUEditApp::CreateDocumentfromHandle(Handle theData)
- {
- GNUEditDoc *theDocument = NULL;
-
- // In the event that creating the document fails,
- // we setup an exception handler here. If any
- // of the methods called within the scope of this
- // TRY block fail, an exception will be raised and
- // control will be transferred to the CATCH block.
- // Here, the CATCH block takes care of disposing
- // of the partially created document.
-
- TRY
- {
- theDocument = new(GNUEditDoc);
-
- /**
- ** Send your document an initialization
- ** message. The first argument is the
- ** supervisor (the application). The second
- ** argument is TRUE if the document is printable.
- **
- **/
-
- theDocument->IGNUEditDoc(this, TRUE);
-
- /**
- ** Send the document a NewFile() message.
- ** The document will open a window, and
- ** set up the heart of the application.
- **
- **/
- theDocument->NewFilefromHandle(theData);
- }
- CATCH
- {
- ForgetObject( theDocument);
- }
- ENDTRY;
- }
-
- /***
- * OpenDocument
- *
- * The user chose Open… from the File menu.
- * In this method you need to create a document
- * and send it an OpenFile() message.
- *
- * The macSFReply is a good SFReply record that contains
- * the name and vRefNum of the file the user chose to
- * open.
- *
- ***/
-
- void GNUEditApp::OpenDocument(SFReply *macSFReply)
- {
- CDocument *newDoc = NULL;
- TRY
- {
- switch( macSFReply->fType)
- {
- case 'TEXT':
- {
- GNUEditDoc *textDoc = new(GNUEditDoc);
- newDoc = textDoc;
- textDoc->IGNUEditDoc(this, TRUE);
- textDoc->OpenFile(macSFReply);
- break;
- }
- case 'AR ':
- {
- CObjectDoc *textDoc = new(CObjectDoc);
- newDoc = textDoc;
- textDoc->IObjectDoc(this, TRUE);
- textDoc->OpenFile(macSFReply);
- break;
- }
- default:
- {
- CBrowseResDoc *resDoc = new(CBrowseResDoc);
- newDoc = resDoc;
- resDoc->IBrowseResDoc( this, TRUE);
- resDoc->OpenFile(macSFReply);
- break;
- }
- }
- }
- CATCH
- {
- ForgetObject( newDoc);
- }
- ENDTRY;
- }
-
- /******************************************************************************
- StartUpAction {OVERRIDE}
-
- Perform any desired start up action. This method is invoked after
- files selected from the Finder have been opened/printed. The number
- of preloaded files is passed as a parameter. If no files were
- preloaded, this default method acts as if the user selected "New"
- and sends the Gopher a DoCommand(cmdNew) message.
- ******************************************************************************/
-
- void GNUEditApp::StartUpAction(short numPreloads)
- {
- short vRefNum;
- long dirID;
- Str255 fileName = {"\pgcc preferences"};
- OSErr err;
- Handle optH;
-
- FlushEvents(everyEvent, 0);
-
- /* override usual method - no default window */
- FailOSErr(FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&vRefNum,&dirID));
- HCreateResFile(vRefNum,dirID,fileName);
- err = ResError();
- prefsRefNum = HOpenResFile(vRefNum,dirID,fileName,fsCurPerm);
- gStrings = new( CPathArray);
- gStrings->IRes( 1024 );
-
- optH = GetResource( 'PREF', 20000);
- BlockMove(*optH, gOptions, sizeof(gOptions));
-
- /* if no preferences file, assume running for the first time, display About Box */
- if (!err)
- {
- FInfo fndrInfo;
- HGetFInfo(vRefNum,dirID,fileName,&fndrInfo);
- fndrInfo.fdType = 'PREF';
- fndrInfo.fdCreator = gSignature;
- HSetFInfo(vRefNum,dirID,fileName,&fndrInfo);
- DoCommand(256);
- }
- }
-
- /******************************************************************************
- DoAppleEvent {OVERRIDE}
-
- Respond to an AppleEvent. This method handles the four required
- AppleEvents: kAEOpenApplication, kAEOpenDocuments, kAEPrintDocuments,
- and kAEQuitApplication.
-
- ******************************************************************************/
-
- void GNUEditApp::DoAppleEvent( CAppleEvent *anAppleEvent)
- {
- DescType eventClass;
- DescType eventID;
- OSErr err;
-
- eventClass = anAppleEvent->GetEventClass();
- eventID = anAppleEvent->GetEventID();
-
- if ((eventClass == kCoreEventClass) && (eventID == kAEOpenApplication))
- {
- if (anAppleEvent->GotRequiredParams())
- {
- anAppleEvent->SetErrorResult( noErr);
- }
- }
- else inherited::DoAppleEvent( anAppleEvent);
- }
-
- int gestalt_test (int);
-
- #define MIN_MAJOR 7
-
- main()
- {
- GNUEditApp *editApp;
- if (gestalt_test(MIN_MAJOR) >= MIN_MAJOR)
- {
- editApp = new(GNUEditApp);
- editApp->IGNUEditApp();
- editApp->Run();
- editApp->Exit();
- }
- }
-
- void spin(void);
-
- void spin(void)
- {
- ((GNUEditApp *)gApplication)->SpinCursor();
- }
-
- static void CDRVRList(CObject *theObject, long destHandle)
- {
- CWindow *theWindow = (CWindow *)theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, CDRVRDirector))
- {
- Str255 theTitle;
- theWindow->GetTitle(theTitle);
- theTitle[1+*theTitle] = 0;
- FailOSErr(PtrAndHand(theTitle,(Handle)destHandle,2+*theTitle));
- }
- }
-
- static void CARList(CObject *theObject, long destHandle)
- {
- CWindow *theWindow = (CWindow *)theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, CObjectDoc))
- {
- Str255 theTitle;
- theWindow->GetTitle(theTitle);
- theTitle[1+*theTitle] = 0;
- FailOSErr(PtrAndHand(theTitle,(Handle)destHandle,2+*theTitle));
- }
- }
-
- static void CDRVRBrowserList(CObject *theObject, long destHandle)
- {
- register CWindow *theWindow = (CWindow *)theObject;
- CDirector *theDirector = (CDirector*) theWindow->GetSupervisor();
- if (member(theDirector, CDRVRBrowser))
- {
- CDRVRBrowser *theDocument = (CDRVRBrowser *)theDirector;
- tResourceInfo resInfo;
- Cell selectedCell;
- // determine the selected cells
-
- selectedCell.h = selectedCell.v = 0;
- while (theDocument->GetSelect( kCurrentOrNext, &selectedCell, &resInfo))
- {
- if (!*defaultLibname) theWindow->GetTitle(defaultLibname);
- resInfo.name[1+*resInfo.name] = 0;
- resInfo.name[1] = *resInfo.name-1;
- FailOSErr(PtrAndHand(&resInfo.name[1],(Handle)destHandle,1+*resInfo.name));
- }
- }
- }
-
- void GNUEditApp::DoCommand( long theCommand)
- {
- CDirector *director;
- CWindow *window;
-
- switch( theCommand)
- {
- case 256: /* about box */
- case 257: /* help box */
- case 258: /* COPYING */
- {
- CAboutDirector *dialog = NULL;
- TRY
- {
- dialog = new CAboutDirector;
- dialog->IAboutDirector((short)theCommand, gApplication);
- dialog->BeginDialog();
- }
- CATCH
- {
- ForgetObject( dialog);
- }
- ENDTRY;
- break;
- }
- case configCPP :
- case configCC1 :
- case configAS :
- case configLD :
- {
- CConfigDirector *dialog = NULL;
- TRY
- {
- dialog = new CConfigDirector;
- dialog->IConfigDirector((short)theCommand, gApplication);
- dialog->BeginDialog();
- }
- CATCH
- {
- ForgetObject( dialog);
- }
- ENDTRY;
- break;
- }
- case configSEARCH:
- {
- CPathDirector *dialog = NULL;
- TRY
- {
- dialog = new CPathDirector;
- dialog->IPathDirector();
- dialog->BeginDialog();
- }
- CATCH
- {
- ForgetObject( dialog);
- }
- ENDTRY;
- break;
- }
- case cmdLD: case cmdLDR: case cmdAR:
- {
- Str255 theInput,theOutput;
- void munge(int, char **, int (*)(int,char **), Handle, short);
- int ld_main(int, char **);
- int ar_main(int, char **);
- char *argv[999];
- int i,argc = 0;
- Handle stdin = NewHandle(0);
- Handle args = NewHandle(0);
- if (theCommand == cmdAR)
- {
- argv[argc++] = "ar";
- argv[argc++] = "rcs";
- argv[argc++] = "library.a";
- }
- else
- {
- argv[argc++] = "ld";
- argv[argc++] = "-r";
- argv[argc++] = "-d";
- }
- if (theCommand == cmdLDR)
- {
- argv[argc++] = "-o";
- argv[argc++] = "linker.o";
- }
- gDesktop->itsWindows->DoForEach1(CDRVRList, (long)args);
- *defaultLibname = 0;
- gDesktop->itsWindows->DoForEach1(CDRVRBrowserList, (long)args);
- if (theCommand != cmdAR)
- {
- gDesktop->itsWindows->DoForEach1(CARList, (long)args);
- gDesktop->itsWindows->DoForEach1(CARList, (long)args);
- }
- HLockHi(args);
- {
- char *ptr = *args;
- while (ptr < GetHandleSize(args)+*args)
- {
- argv[argc++] = ptr+1;
- ptr += 2+*ptr;
- }
- }
- argv[argc] = 0;
- if (theCommand == cmdAR)
- munge(argc,argv,ar_main,stdin,cmdAR);
- else
- munge(argc,argv,ld_main,stdin,cmdLD);
- DisposHandle(args);
- DisposHandle(stdin);
- break;
- }
- default:
- inherited::DoCommand( theCommand);
- break;
- }
- }
-